import vue from '@vitejs/plugin-vue';
import vueJSX from '@vitejs/plugin-vue-jsx';
import vueSetupExtend from 'vite-plugin-vue-setup-extend';
import createAutoImport from './plugin/unplugin-auto-import';
import createComponents from './plugin/unplugin-vue-components';
import createViteEslintPlugin from './plugin/vite-plugin-eslint';
import createVitePluginProgress from './plugin/vite-plugin-progress';
import createViteVisualPlugin from './plugin/rollup-plugin-visualizer';
import createViteHtmlPlugin from './plugin/vite-plugin-html-transform';
import { setPreLoadFile as viteLoadPlugin } from './plugin/vite-plugin-preload';

export default function vitePlugins(viteEnv) {
  const { VITE_USER_NODE_ENV } = viteEnv;
  const isBuild = VITE_USER_NODE_ENV === 'production';

  const vitePlugins = [
    vue(),
    vueJSX(),
    vueSetupExtend(),
    viteLoadPlugin({
      pathList: ['./src/views/'],
      preFix: ''
    })
  ];

  vitePlugins.push(createAutoImport());
  vitePlugins.push(createComponents());
  vitePlugins.push(createViteEslintPlugin());
  vitePlugins.push(createViteHtmlPlugin(viteEnv));
  isBuild && vitePlugins.push(createVitePluginProgress());
  isBuild && vitePlugins.push(createViteVisualPlugin());

  return vitePlugins;
}
